/*
** parseur_xml2.c for  in /home/lucas/projet/philosophe/laidfilauxzauphe
** 
** Made by Lucas Stefas
** Login   <stefas_l@epitech.net>
** 
** Started on  Sat Apr 30 10:05:57 2011 Lucas Stefas
** Last update Sat Apr 30 10:05:58 2011 Lucas Stefas
*/

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

char	*epurstr(char *str)
{
  int	i = 0;
  int	ii = 0;

  while (str[i])
    {
      if (str[i] != ' ' && str[i] != '\t' && str[i] != '\n')
	{
	  str[ii] = str[i];
	  ii += 1;
	}
      i += 1;
    }
  str[ii] = '\0';
  return (str);
}


int	findouverture(char *str, int *start)
{
  int	i = 0;

  while (str[i])
    {
      if (str[i] == '<' && str[i + 1] != '/')
	{
	  *start = i;
	  while (str[i] && str[i] != '>')
	    i += 1;
	  if (str[i] != '\0')
	    return (i);
	}
      i += 1;
    }
  return (-1);
}

int	findfermeture(char *str, int *end)
{
  int	i = 0;
  int	start = 0;

  while (str[i])
    {
      if (str[i] == '<' && str[i + 1] == '/')
	{
	  start = i;
	  while (str[i] && str[i] != '>')
	    i += 1;
	  if (str[i] != '\0')
	    {
	      *end = i;
	      return (start);
	    }
	}
      i += 1;
    }
  return (-1);
}

char	*getbalisename(char *str, int namelen)
{
  int	i = 1;
  char	*newstr;

  if (str[namelen] == '>' && str[0] == '<')
    {
      if ((newstr = malloc(sizeof(char) * namelen)) == NULL)
	{
	  fprintf(stderr, "Error: %s\n", strerror(errno));
	  exit(EXIT_FAILURE);
	}
      while (i != namelen)
	{
	  newstr[i - 1] = str[i];
	  i += 1;
	}
      return (newstr);
    }
  return (NULL);
}

int	my_strcmp(char *str1, char *str2)
{
  int	i = 0;
  
  while (str1[i] && str2[i])
    {
      if (str1[i] != str2[i])
	return (0);
      i += 1;
    }
  if (str1[i] != str2[i])
    return (0);
  return (1);
}
